﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.Common;
using System.Data;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using TRPOP.CRM.Component.Model;
using TRPOP.Common;

namespace TRPOP.CRM.Component.DALSQLServer
{
    public class EmployeeDAL
    {

        private static TRPOP.ComSqlDAL.ICommonDAL CommonDAL = new TRPOP.ComSqlDAL.CommonDAL();
        #region 私有的方法
        ///	<summary>
        ///	从Table取数据到实体
        ///	</summary>
        ///	<param name="oDataRow">数据行</param>
        ///	<returns>返回实体</returns>
        private static EmployeeInfo ParseRowTomodel(DataRow oDataRow)
        {
            EmployeeInfo oInfo = new EmployeeInfo();
            oInfo.iDepartmentID = oDataRow["iDepartmentID"] is DBNull ? 0 : (int)oDataRow["iDepartmentID"];
            oInfo.iEmployeeStatusID = oDataRow["iEmployeeStatusID"] is DBNull ? 0 : (int)oDataRow["iEmployeeStatusID"];
            oInfo.iJobTitleID = oDataRow["iJobTitleID"] is DBNull ? 0 : (int)oDataRow["iJobTitleID"];
            oInfo.nvcEmployeeName = oDataRow["nvcEmployeeName"] is DBNull ? "" : (string)oDataRow["nvcEmployeeName"];
            oInfo.nvcEmployeeNumber = oDataRow["nvcEmployeeNumber"] is DBNull ? "" : (string)oDataRow["nvcEmployeeNumber"];
            oInfo.bGender = oDataRow["bGender"] is DBNull ? false : (bool)oDataRow["bGender"];
            oInfo.nvcMobile = oDataRow["nvcMobile"] is DBNull ? "" : (string)oDataRow["nvcMobile"];
            oInfo.nvcEmail = oDataRow["nvcEmail"] is DBNull ? "" : (string)oDataRow["nvcEmail"];
            oInfo.bnImageBinary = oDataRow["bnImageBinary"] is DBNull ? null : (byte[])oDataRow["bnImageBinary"];
            oInfo.nvcImageBinaryExtension = oDataRow["nvcImageBinaryExtension"] is DBNull ? "" : (string)oDataRow["nvcImageBinaryExtension"];
            oInfo.dtStartDate = oDataRow["dtStartDate"] is DBNull ? (new DateTime(1900, 1, 1)) : (DateTime)oDataRow["dtStartDate"];
            oInfo.dtEndDate = oDataRow["dtEndDate"] is DBNull ? (new DateTime(1900, 1, 1)) : (DateTime)oDataRow["dtEndDate"];
            oInfo.nvcDiscription = oDataRow["nvcDiscription"] is DBNull ? "" : (string)oDataRow["nvcDiscription"];
            oInfo.nvcRemark = oDataRow["nvcRemark"] is DBNull ? "" : (string)oDataRow["nvcRemark"];
            oInfo.dtLastModified = oDataRow["dtLastModified"] is DBNull ? (new DateTime(1900, 1, 1)) : (DateTime)oDataRow["dtLastModified"];
            oInfo.nvcCountry = oDataRow["nvcCountry"] is DBNull ? "" : (string)oDataRow["nvcCountry"];
            oInfo.nvcProvince = oDataRow["nvcProvince"] is DBNull ? "" : (string)oDataRow["nvcProvince"];
            oInfo.nvcCity = oDataRow["nvcCity"] is DBNull ? "" : (string)oDataRow["nvcCity"];
            oInfo.nvcStreet1 = oDataRow["nvcStreet1"] is DBNull ? "" : (string)oDataRow["nvcStreet1"];
            oInfo.nvcStreet2 = oDataRow["nvcStreet2"] is DBNull ? "" : (string)oDataRow["nvcStreet2"];
            oInfo.nvcPostalCode = oDataRow["nvcPostalCode"] is DBNull ? "" : (string)oDataRow["nvcPostalCode"];
            oInfo.dtBirthday = oDataRow["dtBirthday"] is DBNull ? (new DateTime(1900, 1, 1)) : (DateTime)oDataRow["dtBirthday"];
            oInfo.nvcLunarMonth = oDataRow["nvcLunarMonth"] is DBNull ? "" : (string)oDataRow["nvcLunarMonth"];
            oInfo.nvcLunarDay = oDataRow["nvcLunarDay"] is DBNull ? "" : (string)oDataRow["nvcLunarDay"];
            oInfo.nvcEmergencyContactName = oDataRow["nvcEmergencyContactName"] is DBNull ? "" : (string)oDataRow["nvcEmergencyContactName"];
            oInfo.nvcEmergencyContactPhone1 = oDataRow["nvcEmergencyContactPhone1"] is DBNull ? "" : (string)oDataRow["nvcEmergencyContactPhone1"];
            oInfo.nvcEmergencyContactPhone2 = oDataRow["nvcEmergencyContactPhone2"] is DBNull ? "" : (string)oDataRow["nvcEmergencyContactPhone2"];
            oInfo.bIsSolarBitthday = oDataRow["bIsSolarBitthday"] is DBNull ? false : (bool)oDataRow["bIsSolarBitthday"];
            oInfo.dtCreationTime = oDataRow["dtCreationTime"] is DBNull ? (new DateTime(1900, 1, 1)) : (DateTime)oDataRow["dtCreationTime"];
            oInfo.bIsDelete = oDataRow["bIsDelete"] is DBNull ? false : (bool)oDataRow["bIsDelete"];
            oInfo.nvcLoginPassword = oDataRow["nvcLoginPassword"] is DBNull ? "" : (string)oDataRow["nvcLoginPassword"];
            oInfo.bEnableLogin = oDataRow["bEnableLogin"] is DBNull ? false : (bool)oDataRow["bEnableLogin"];
            oInfo.dtLastLoginTime = oDataRow["dtLastLoginTime"] is DBNull ? (new DateTime(1900, 1, 1)) : (DateTime)oDataRow["dtLastLoginTime"];
            oInfo.ntExtendedProperity = oDataRow["ntExtendedProperity"] is DBNull ? "" : (string)oDataRow["ntExtendedProperity"];
            oInfo.iEmployeeID = oDataRow["iEmployeeID"] is DBNull ? 0 : (int)oDataRow["iEmployeeID"];
            return oInfo;
        }


        ///	<summary>
        ///	通用的添加存储过程的变量
        ///	</summary>
        ///	<param name="osdDataBase">SqlDatabase</param>
        ///	<param name="odbCommand">DbCommand</param>
        ///	<param name="oInfo">实体</param>
        private static EmployeeInfo ParseModeltoParam(SqlDatabase odbDataBase, DbCommand odbCommand, EmployeeInfo oInfo)
        {
            odbDataBase.AddInParameter(odbCommand, "@iDepartmentID", System.Data.DbType.Int32, oInfo.iDepartmentID);
            odbDataBase.AddInParameter(odbCommand, "@iEmployeeStatusID", System.Data.DbType.Int32, oInfo.iEmployeeStatusID);
            odbDataBase.AddInParameter(odbCommand, "@iJobTitleID", System.Data.DbType.Int32, oInfo.iJobTitleID);
            odbDataBase.AddInParameter(odbCommand, "@nvcEmployeeName", System.Data.DbType.String, oInfo.nvcEmployeeName);
            odbDataBase.AddInParameter(odbCommand, "@nvcEmployeeNumber", System.Data.DbType.String, oInfo.nvcEmployeeNumber);
            odbDataBase.AddInParameter(odbCommand, "@bGender", System.Data.DbType.Boolean, oInfo.bGender);
            odbDataBase.AddInParameter(odbCommand, "@nvcMobile", System.Data.DbType.String, oInfo.nvcMobile);
            odbDataBase.AddInParameter(odbCommand, "@nvcEmail", System.Data.DbType.String, oInfo.nvcEmail);
            odbDataBase.AddInParameter(odbCommand, "@bnImageBinary", System.Data.DbType.Binary, oInfo.bnImageBinary);
            odbDataBase.AddInParameter(odbCommand, "@nvcImageBinaryExtension", System.Data.DbType.String, oInfo.nvcImageBinaryExtension);
            odbDataBase.AddInParameter(odbCommand, "@dtStartDate", System.Data.DbType.DateTime, oInfo.dtStartDate);
            odbDataBase.AddInParameter(odbCommand, "@dtEndDate", System.Data.DbType.DateTime, oInfo.dtEndDate);
            odbDataBase.AddInParameter(odbCommand, "@nvcDiscription", System.Data.DbType.String, oInfo.nvcDiscription);
            odbDataBase.AddInParameter(odbCommand, "@nvcRemark", System.Data.DbType.String, oInfo.nvcRemark);
            odbDataBase.AddInParameter(odbCommand, "@dtLastModified", System.Data.DbType.DateTime, oInfo.dtLastModified);
            odbDataBase.AddInParameter(odbCommand, "@nvcCountry", System.Data.DbType.String, oInfo.nvcCountry);
            odbDataBase.AddInParameter(odbCommand, "@nvcProvince", System.Data.DbType.String, oInfo.nvcProvince);
            odbDataBase.AddInParameter(odbCommand, "@nvcCity", System.Data.DbType.String, oInfo.nvcCity);
            odbDataBase.AddInParameter(odbCommand, "@nvcStreet1", System.Data.DbType.String, oInfo.nvcStreet1);
            odbDataBase.AddInParameter(odbCommand, "@nvcStreet2", System.Data.DbType.String, oInfo.nvcStreet2);
            odbDataBase.AddInParameter(odbCommand, "@nvcPostalCode", System.Data.DbType.String, oInfo.nvcPostalCode);
            odbDataBase.AddInParameter(odbCommand, "@dtBirthday", System.Data.DbType.DateTime, oInfo.dtBirthday);
            odbDataBase.AddInParameter(odbCommand, "@nvcLunarMonth", System.Data.DbType.String, oInfo.nvcLunarMonth);
            odbDataBase.AddInParameter(odbCommand, "@nvcLunarDay", System.Data.DbType.String, oInfo.nvcLunarDay);
            odbDataBase.AddInParameter(odbCommand, "@nvcEmergencyContactName", System.Data.DbType.String, oInfo.nvcEmergencyContactName);
            odbDataBase.AddInParameter(odbCommand, "@nvcEmergencyContactPhone1", System.Data.DbType.String, oInfo.nvcEmergencyContactPhone1);
            odbDataBase.AddInParameter(odbCommand, "@nvcEmergencyContactPhone2", System.Data.DbType.String, oInfo.nvcEmergencyContactPhone2);
            odbDataBase.AddInParameter(odbCommand, "@bIsSolarBitthday", System.Data.DbType.Boolean, oInfo.bIsSolarBitthday);
            odbDataBase.AddInParameter(odbCommand, "@dtCreationTime", System.Data.DbType.DateTime, oInfo.dtCreationTime);
            odbDataBase.AddInParameter(odbCommand, "@bIsDelete", System.Data.DbType.Boolean, oInfo.bIsDelete);
            odbDataBase.AddInParameter(odbCommand, "@nvcLoginPassword", System.Data.DbType.String, oInfo.nvcLoginPassword);
            odbDataBase.AddInParameter(odbCommand, "@bEnableLogin", System.Data.DbType.Boolean, oInfo.bEnableLogin);
            odbDataBase.AddInParameter(odbCommand, "@dtLastLoginTime", System.Data.DbType.DateTime, oInfo.dtLastLoginTime);
            odbDataBase.AddInParameter(odbCommand, "@ntExtendedProperity", System.Data.DbType.String, oInfo.ntExtendedProperity);
            odbDataBase.AddParameter(odbCommand, "@iEmployeeID", System.Data.DbType.Int32, ParameterDirection.InputOutput, null, DataRowVersion.Default, oInfo.iEmployeeID);
            return oInfo;
        }


        #endregion

        ///	<summary>
        ///	 更新或添加
        ///	</summary>
        ///	<param name="oInfo"></param>
        ///	<returns>bool</returns>
        public bool Save(EmployeeInfo oInfo)
        {
            bool flag = false;
            try
            {
                SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().DataBaseConnection);
                DbCommand odbCommand = odbDataBase.GetStoredProcCommand("Employee_Save");
                ParseModeltoParam(odbDataBase, odbCommand, oInfo);
                odbDataBase.ExecuteNonQuery(odbCommand);
                oInfo.iEmployeeID = (int)odbDataBase.GetParameterValue(odbCommand, "@iEmployeeID");
                flag = true;
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return flag;
        }

        ///	<summary>
        ///	根据Primary Key获取信息实体
        ///	</summary>
        ///	<param name="intiEmployeeID"></param>
        ///	<returns>EmployeeInfo</returns>
        public EmployeeInfo GetInfoById(int intiEmployeeID)
        {
            EmployeeInfo oInfo = null;
            string strSqlString = "SELECT * FROM Employee WHERE  iEmployeeID=" + intiEmployeeID + "    ";
            try
            {
                DataSet oDataSet = CommonDAL.GetDataSet(strSqlString, SystemInfoHelper.getSystemInfo().DataBaseConnection);
                DataTable oDataTable = oDataSet.Tables[0];
                if (oDataTable.Rows.Count == 1)
                {
                    oInfo = ParseRowTomodel(oDataTable.Rows[0]);
                }
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return oInfo;
        }

        ///	<summary>
        ///	 根据Primary Key删除信息实体
        ///	</summary>
        ///	<param name="intiEmployeeID"></param>
        ///	<returns>bool</returns>
        public bool DeleteInfoById(int intiEmployeeID)
        {
            return DeleteInfoByIds(intiEmployeeID.ToString());
        }

        /// <summary>
        ///根据用户Id，批量删除
        /// </summary>
        /// <param name="strIDs">多个Id，Id之间用“,”隔开</param>
        /// <returns></returns>
        public bool DeleteInfoByIds(string strEmployeeIDs)
        {
            string strSqlString = "UPDATE Employee SET bIsDelete=1 WHERE iEmployeeID in(" + strEmployeeIDs + " )";

            try
            {
                if (CommonDAL.ExeSQLQuery(strSqlString, SystemInfoHelper.getSystemInfo().DataBaseConnection) == EnumSubmitResult.Success)
                {
                    strSqlString = "UPDATE Company SET iCompanyStatus = 2 Where iEmployeeFollowup in ( " + strEmployeeIDs + " ) ";
                    try
                    {
                        if (CommonDAL.ExeSQLQuery(strSqlString, SystemInfoHelper.getSystemInfo().DataBaseConnection) == EnumSubmitResult.Success)
                        {
                            strSqlString = "UPDATE Company SET iEmployeeFollowup = 1 , iCompanySourceID =1 Where iEmployeeFollowup ( " + strEmployeeIDs + " ) ";
                            CommonDAL.ExeSQLQuery(strSqlString, SystemInfoHelper.getSystemInfo().DataBaseConnection);
                        }
                    }
                    catch
                    {

                    };

                    return true;
                }
                else
                    return false;
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
        }

        ///	<summary>
        ///	 获取信息列表（无分页）
        ///	</summary>
        ///	<param name="intTopn">前N条，为0时表示所有符合条件的</param>
        ///	<param name="strCondition">自定义条件，要以And开头</param>
        ///	<param name="strOrderby">排序，不需要Order by </param>
        ///	<returns>List<EmployeeInfo></returns>
        public List<EmployeeInfo> GetListByCondition(int intTopn, string strCondition, string strOrderby)
        {
            List<EmployeeInfo> oList = new List<EmployeeInfo>();
            string strSql = CommonDAL.strbuildSqlForList(intTopn, strCondition, strOrderby, "Employee");
            try
            {
                DataSet oDataSet = CommonDAL.GetDataSet(strSql, SystemInfoHelper.getSystemInfo().DataBaseConnection);
                DataTable oDataTable = oDataSet.Tables[0];
                foreach (DataRow otempRow in oDataTable.Rows)
                {
                    oList.Add(ParseRowTomodel(otempRow));
                }
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return oList;
        }

        ///	<summary>
        ///	获取分页信息
        ///	</summary>
        /// <param name="intPageNumber">当前页页码</param>
        /// <param name="intPageSize">分页大小</param>
        /// <param name="strCondition">查询条件 and ....</param>
        /// <param name="strOrderby">排序的字段名 id desc</param>
        /// <param name="intRecordCount">总记录数</param>
        ///	<returns>List<EmployeeInfo></returns>
        public List<EmployeeInfo> GetListByPager(int intPageNumber, int intPageSize, string strCondition, string strOrderby, out int intRecordCount)
        {
            List<EmployeeInfo> oList = new List<EmployeeInfo>();
            try
            {
                DataSet oDataSet = CommonDAL.GetListByPager("Employee", "*", intPageNumber, intPageSize, strCondition, strOrderby, out  intRecordCount, SystemInfoHelper.getSystemInfo().DataBaseConnection);
                DataTable oDataTable = oDataSet.Tables[0];
                foreach (DataRow otempRow in oDataTable.Rows)
                {
                    oList.Add(ParseRowTomodel(otempRow));
                }
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return oList;
        }

        /// <summary>
        /// 根据用户名和密码 获取 所有的 EmployeeInfo
        /// </summary>
        /// <param name="strname"></param>
        /// <param name="strPWD"></param>
        /// <returns></returns>
        public List<EmployeeInfo> GetEmployeeInfosByNamePWD(string strname, string strPWD)
        {
            string strCondation = string.Format("AND bIsDelete=0  AND bEnableLogin=1 AND nvcEmployeeName='{0}' AND nvcLoginPassword='{1}' ", strname, strPWD);
            return GetListByCondition(0, strCondation, string.Empty);
        }

        #region EmployeeSimpleInfo
        /// <summary>
        /// 获取 员工信息 为了列表显示
        /// </summary>
        /// <param name="intPageNumber"></param>
        /// <param name="intPageSize"></param>
        /// <param name="strCondition"></param>
        /// <param name="strOrderby"></param>
        /// <param name="intRecordCount"></param>
        /// <returns></returns>
        public List<EmployeeSimpleInfo> GetEmployeeSimpleInfoPager(int intPageNumber, int intPageSize, string strCondition, string strOrderby, out int intRecordCount)
        {
            if (strOrderby.IsEmpty())
            {
                strOrderby = " iEmployeeID DESC";
            }

            strCondition += " AND  bIsDelete=0 ";

            List<EmployeeSimpleInfo> oList = new List<EmployeeSimpleInfo>();

            try
            {
                DataSet oDataSet = CommonDAL.GetListByPager("vw_Employee", "*", intPageNumber, intPageSize, strCondition, strOrderby, out  intRecordCount, SystemInfoHelper.getSystemInfo().DataBaseConnection);
                DataTable oDataTable = oDataSet.Tables[0];
                foreach (DataRow otempRow in oDataTable.Rows)
                {
                    oList.Add(ParseRowToEmployeeSimpleInfo(otempRow));
                }
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }

            return oList;
        }
        private static EmployeeSimpleInfo ParseRowToEmployeeSimpleInfo(DataRow oDataRow)
        {
            EmployeeSimpleInfo oInfo = new EmployeeSimpleInfo();

            oInfo.nvcDepartment = oDataRow["nvcDepartmentName"] is DBNull ? "" : (string)oDataRow["nvcDepartmentName"];
            oInfo.nvcEmployeeStatus = oDataRow["nvcStatusName"] is DBNull ? "" : (string)oDataRow["nvcStatusName"];
            oInfo.nvcJobTitle = oDataRow["nvcJobTitleName"] is DBNull ? "" : (string)oDataRow["nvcJobTitleName"];
            oInfo.nvcEmployeeName = oDataRow["nvcEmployeeName"] is DBNull ? "" : (string)oDataRow["nvcEmployeeName"];
            oInfo.nvcEmployeeNumber = oDataRow["nvcEmployeeNumber"] is DBNull ? "" : (string)oDataRow["nvcEmployeeNumber"];
            oInfo.bGender = oDataRow["bGender"] is DBNull ? false : (bool)oDataRow["bGender"];
            oInfo.nvcMobile = oDataRow["nvcMobile"] is DBNull ? "" : (string)oDataRow["nvcMobile"];
            oInfo.nvcEmail = oDataRow["nvcEmail"] is DBNull ? "" : (string)oDataRow["nvcEmail"];
            oInfo.dtStartDate = oDataRow["dtStartDate"] is DBNull ? (new DateTime(1900, 1, 1)) : (DateTime)oDataRow["dtStartDate"];
            oInfo.dtEndDate = oDataRow["dtEndDate"] is DBNull ? (new DateTime(1900, 1, 1)) : (DateTime)oDataRow["dtEndDate"];
            oInfo.bIsDelete = oDataRow["bIsDelete"] is DBNull ? false : (bool)oDataRow["bIsDelete"];
            oInfo.iEmployeeID = oDataRow["iEmployeeID"] is DBNull ? 0 : (int)oDataRow["iEmployeeID"];

            return oInfo;
        }
        #endregion

        #region check EmployeeInfo

        /// <summary>
        /// 检测EmployeeNumber是否已存在
        /// </summary>
        /// <param name="strEmployeeNumber">EmployeeNumber</param>
        /// <returns>True：已存在；False：不存在</returns>
        public bool CheckEmployeeNumberExist(string strEmployeeNumber)
        {
            bool bReturn = false;

            string strSqlString = "SELECT * FROM Employee WHERE nvcEmployeeNumber='" + strEmployeeNumber + "'";
            try
            {
                DataSet oDataSet = CommonDAL.GetDataSet(strSqlString, SystemInfoHelper.getSystemInfo().DataBaseConnection);
                DataTable oDataTable = oDataSet.Tables[0];
                if (oDataTable.Rows.Count > 0)
                {
                    bReturn = true;
                }
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }

            return bReturn;
        }

        /// <summary>
        /// 检测EmployeeName是否已存在
        /// </summary>
        /// <param name="strEmployeeNumber">EmployeeNumber</param>
        /// <returns>True：已存在；False：不存在</returns>
        public bool CheckEmployeeNameExist(string strEmployeeName)
        {
            bool bReturn = false;

            string strSqlString = "SELECT * FROM Employee WHERE nvcEmployeeName='" + strEmployeeName + "'";
            try
            {
                DataSet oDataSet = CommonDAL.GetDataSet(strSqlString, SystemInfoHelper.getSystemInfo().DataBaseConnection);
                DataTable oDataTable = oDataSet.Tables[0];
                if (oDataTable.Rows.Count > 0)
                {
                    bReturn = true;
                }
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }

            return bReturn;
        }
        #endregion

        #region 销售额
        /// <summary>
        /// 
        /// </summary>
        /// <param name="intPageNumber"></param>
        /// <param name="intPageSize"></param>
        /// <param name="strCondition"></param>
        /// <param name="strOrderby"></param>
        /// <param name="intRecordCount"></param>
        /// <returns></returns>
        public List<EmployeeSaleTotalInfo> GetEmployeeTitleInfoPager(int intPageNumber, int intPageSize, string strCondition, string strOrderby, out int intRecordCount)
        {
            if (strOrderby.IsEmpty())
            {
                strOrderby = "TotalNum DESC";
            }
            strCondition += " AND  bIsDelete=0 ";
            List<EmployeeSaleTotalInfo> oList = new List<EmployeeSaleTotalInfo>();

            try
            {
                DataSet oDataSet = CommonDAL.GetListByPager("vw_SaleTopToday", "*", intPageNumber, intPageSize, strCondition, strOrderby, out  intRecordCount, SystemInfoHelper.getSystemInfo().DataBaseConnection);
                DataTable oDataTable = oDataSet.Tables[0];
                foreach (DataRow otempRow in oDataTable.Rows)
                {
                    oList.Add(ParseRowToEmployeeSaleTotalInfo(otempRow));
                }
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }

            return oList;
        }
        private static EmployeeSaleTotalInfo ParseRowToEmployeeSaleTotalInfo(DataRow oDataRow)
        {
            EmployeeSaleTotalInfo oInfo = new EmployeeSaleTotalInfo();

            oInfo.nvcDepartment = oDataRow["nvcDepartmentName"] is DBNull ? "" : (string)oDataRow["nvcDepartmentName"];
            oInfo.nvcEmployeeStatus = oDataRow["nvcStatusName"] is DBNull ? "" : (string)oDataRow["nvcStatusName"];
            oInfo.nvcJobTitle = oDataRow["nvcJobTitleName"] is DBNull ? "" : (string)oDataRow["nvcJobTitleName"];
            oInfo.nvcEmployeeName = oDataRow["nvcEmployeeName"] is DBNull ? "" : (string)oDataRow["nvcEmployeeName"];
            oInfo.nvcEmployeeNumber = oDataRow["nvcEmployeeNumber"] is DBNull ? "" : (string)oDataRow["nvcEmployeeNumber"];
            oInfo.bGender = oDataRow["bGender"] is DBNull ? false : (bool)oDataRow["bGender"];
            oInfo.nvcMobile = oDataRow["nvcMobile"] is DBNull ? "" : (string)oDataRow["nvcMobile"];
            oInfo.nvcEmail = oDataRow["nvcEmail"] is DBNull ? "" : (string)oDataRow["nvcEmail"];
            oInfo.dtStartDate = oDataRow["dtStartDate"] is DBNull ? (new DateTime(1900, 1, 1)) : (DateTime)oDataRow["dtStartDate"];
            oInfo.dtEndDate = oDataRow["dtEndDate"] is DBNull ? (new DateTime(1900, 1, 1)) : (DateTime)oDataRow["dtEndDate"];
            oInfo.bIsDelete = oDataRow["bIsDelete"] is DBNull ? false : (bool)oDataRow["bIsDelete"];
            oInfo.iEmployeeID = oDataRow["iEmployeeID"] is DBNull ? 0 : (int)oDataRow["iEmployeeID"];

            oInfo.TotalNum = oDataRow["TotalNum"] is DBNull ? 0 : (int)oDataRow["TotalNum"];

            return oInfo;
        }
        #endregion
    }
}
